package com.action.impl;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.struts2.ServletActionContext;
import com.app.business.ReadExcelAndRequestTaobao;
import com.utils.ConfigManager;
import com.utils.Constants;
import com.utils.PagesUtil;
import com.utils.UtilsFile;

public class HandlerAction extends BaseAction{
	private String filename;
	private String field_textarea;
	
	public void exec(){
		String filePath= ServletActionContext.getServletContext().getRealPath("/upfile");
		File file = new File(filePath+"/"+filename);
		ReadExcelAndRequestTaobao readExcelAndRequestTaobao = new ReadExcelAndRequestTaobao();
		readExcelAndRequestTaobao.execute(file);
		
		PagesUtil.outDataToPage("{\"flag\":\"true\"}");
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}
	
	
	public void getHandlerLogs(){
		filename = Constants.USER_LOG;
		String logs;
		try {
			logs = UtilsFile.readFile(Constants.APP_LOG_PATH + filename).toString();
			boolean over = false;
			if(logs.indexOf("[over!]") != -1){
				over = true;
			}
			PagesUtil.outDataToPage("{\"over\":\""+over+"\",\"logs\":\""+logs+"\"}");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void reloadConfig(){
		ConfigManager.initConfig();
		
		PagesUtil.outOKToPage();
	}
	
	public void saveMapping(){
		UtilsFile.LogToFile(new File(Constants.APP_CONFIGFILE_PATH + filename), field_textarea, false);
		
		PagesUtil.outOKToPage();
	}
	public void queryMapping(){
		String context;
		try {
			context = UtilsFile.readFile(Constants.APP_CONFIGFILE_PATH + filename).toString().replaceAll("\r\n", "<br/>").trim();
//			System.out.println(context);
			PagesUtil.outDataToPage("{\"context\":\""+context+"\"}");
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public String getField_textarea() {
		return field_textarea;
	}

	public void setField_textarea(String field_textarea) {
		this.field_textarea = field_textarea;
	}

	public void xmlTree(){
		PagesUtil.outDataToPage("<itemprops_get_response><item_props list='true'><item_prop><multi>false</multi><must>false</must><name>货号</name><pid>1632501</pid></item_prop><item_prop><multi>false</multi><must>true</must><name>款式</name><pid>1628072</pid><prop_values list='true'><prop_value><name>套头</name><vid>103422</vid></prop_value><prop_value><name>开衫</name><vid>103423</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>板型</name><pid>1627739</pid><prop_values list='true'><prop_value><name>宽松型(腰围胸围)</name><vid>3267161</vid></prop_value><prop_value><name>修身型</name><vid>3267162</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>男装厚薄</name><pid>14043921</pid><prop_values list='true'><prop_value><name>薄款</name><vid>3216783</vid></prop_value><prop_value><name>普通</name><vid>10004</vid></prop_value><prop_value><name>加厚</name><vid>113060</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>true</must><name>领型</name><pid>1627746</pid><prop_values list='true'><prop_value><name>圆领</name><vid>29447</vid></prop_value><prop_value><name>V领</name><vid>29448</vid></prop_value><prop_value><name>门筒领</name><vid>3267221</vid></prop_value><prop_value><name>连帽</name><vid>3267192</vid></prop_value><prop_value><name>高翻领</name><vid>3267223</vid></prop_value><prop_value><name>翻领</name><vid>29449</vid></prop_value><prop_value><name>蹲领/堆堆领</name><vid>136208989</vid></prop_value><prop_value><name>不可翻高领（短筒高领）</name><vid>157297810</vid></prop_value><prop_value><name>半高领</name><vid>29075742</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>风格</name><pid>1627782</pid><prop_values list='true'><prop_value><is_parent>true</is_parent><name>商务休闲</name><vid>112571</vid></prop_value><prop_value><name>时尚休闲</name><vid>3267970</vid></prop_value><prop_value><name>嘻哈风格</name><vid>3325500</vid></prop_value><prop_value><name>英伦风格</name><vid>3288360</vid></prop_value><prop_value><name>运动风格</name><vid>18558881</vid></prop_value><prop_value><name>欧美风格</name><vid>130859</vid></prop_value><prop_value><name>学院风格</name><vid>4328394</vid></prop_value><prop_value><name>商务正装</name><vid>28908344</vid></prop_value><prop_value><name>青春休闲</name><vid>6700169</vid></prop_value><prop_value><name>日韩个性</name><vid>16304925</vid></prop_value><prop_value><name>原创设计</name><vid>3223746</vid></prop_value></prop_values></item_prop><item_prop><multi>true</multi><must>false</must><name>颜色</name><pid>1627207</pid><prop_values list='true'><prop_value><name>军绿色</name><vid>3232483</vid></prop_value><prop_value><name>天蓝色</name><vid>3232484</vid></prop_value><prop_value><name>巧克力色</name><vid>3232481</vid></prop_value><prop_value><name>桔色</name><vid>90554</vid></prop_value><prop_value><name>浅灰色</name><vid>28332</vid></prop_value><prop_value><name>浅绿色</name><vid>30156</vid></prop_value><prop_value><name>浅黄色</name><vid>60092</vid></prop_value><prop_value><name>深卡其布色</name><vid>3232482</vid></prop_value><prop_value><name>深灰色</name><vid>3232478</vid></prop_value><prop_value><name>深紫色</name><vid>3232479</vid></prop_value><prop_value><name>深蓝色</name><vid>28340</vid></prop_value><prop_value><name>白色</name><vid>28320</vid></prop_value><prop_value><name>粉红色</name><vid>3232480</vid></prop_value><prop_value><name>紫罗兰</name><vid>80882</vid></prop_value><prop_value><name>紫色</name><vid>28329</vid></prop_value><prop_value><name>红色</name><vid>28326</vid></prop_value><prop_value><name>绿色</name><vid>28335</vid></prop_value><prop_value><name>花色</name><vid>130164</vid></prop_value><prop_value><name>蓝色</name><vid>28338</vid></prop_value><prop_value><name>褐色</name><vid>132069</vid></prop_value><prop_value><name>透明</name><vid>107121</vid></prop_value><prop_value><name>酒红色</name><vid>28327</vid></prop_value><prop_value><name>黄色</name><vid>28324</vid></prop_value><prop_value><name>黑色</name><vid>28341</vid></prop_value></prop_values></item_prop><item_prop><multi>true</multi><must>false</must><name>尺码</name><pid>1628027</pid><prop_values list='true'><prop_value><name>160/80A</name><vid>3743391</vid></prop_value><prop_value><name>165/85A</name><vid>3271528</vid></prop_value><prop_value><name>170/90A</name><vid>3271530</vid></prop_value><prop_value><name>175/95A</name><vid>3271531</vid></prop_value><prop_value><name>180/100A</name><vid>3267945</vid></prop_value><prop_value><name>185/105A</name><vid>3271533</vid></prop_value><prop_value><name>160/80B</name><vid>25058495</vid></prop_value><prop_value><name>165/85B</name><vid>3271537</vid></prop_value><prop_value><name>170/90B</name><vid>3271540</vid></prop_value><prop_value><name>175/95B</name><vid>3271542</vid></prop_value><prop_value><name>180/100B</name><vid>3267950</vid></prop_value><prop_value><name>185/105B</name><vid>3271544</vid></prop_value><prop_value><name>均码</name><vid>28383</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>款式细节</name><pid>1627773</pid><prop_values list='true'><prop_value><name>假两件</name><vid>130567</vid></prop_value><prop_value><name>纯色</name><vid>29454</vid></prop_value><prop_value><name>色块</name><vid>22054153</vid></prop_value><prop_value><name>徽章</name><vid>94545</vid></prop_value><prop_value><name>撞色</name><vid>130568</vid></prop_value><prop_value><name>贴布装饰</name><vid>3267904</vid></prop_value><prop_value><name>格子</name><vid>29453</vid></prop_value><prop_value><name>条纹</name><vid>29452</vid></prop_value><prop_value><name>扭花</name><vid>3272132</vid></prop_value><prop_value><name>提花</name><vid>130693</vid></prop_value><prop_value><name>肩部贴布</name><vid>136209667</vid></prop_value><prop_value><name>绞花</name><vid>31896313</vid></prop_value><prop_value><name>印花</name><vid>129555</vid></prop_value><prop_value><name>烫钻</name><vid>7019314</vid></prop_value><prop_value><name>嵌花</name><vid>70981956</vid></prop_value><prop_value><name>其它</name><vid>10122</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>工艺处理</name><pid>1627776</pid><prop_values list='true'><prop_value><name>水洗</name><vid>102510</vid></prop_value><prop_value><name>免烫处理</name><vid>3267927</vid></prop_value><prop_value><name>丝光</name><vid>130839</vid></prop_value><prop_value><name>植绒</name><vid>3267928</vid></prop_value><prop_value><name>磨毛</name><vid>130694</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>true</must><name>品牌</name><pid>20000</pid><prop_values list='true'><prop_value><name>Heilan Home/海澜之家</name><vid>103560838</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>袖型</name><pid>14043904</pid><prop_values list='true'><prop_value><name>常规袖</name><vid>27924515</vid></prop_value><prop_value><name>插肩袖</name><vid>27414630</vid></prop_value><prop_value><name>蝙蝠袖</name><vid>7576170</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>季节</name><pid>14043868</pid><prop_values list='true'><prop_value><name>春秋季</name><vid>31341</vid></prop_value><prop_value><name>秋</name><vid>5493699</vid></prop_value><prop_value><name>夏</name><vid>3292677</vid></prop_value><prop_value><name>春</name><vid>3777261</vid></prop_value><prop_value><name>冬</name><vid>5445995</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>男装图案</name><pid>20606</pid><prop_values list='true'><prop_value><name>菱形</name><vid>3716934</vid></prop_value><prop_value><name>条纹</name><vid>29452</vid></prop_value><prop_value><name>格子</name><vid>29453</vid></prop_value><prop_value><name>纯色</name><vid>29454</vid></prop_value><prop_value><name>其它</name><vid>10122</vid></prop_value><prop_value><name>几何</name><vid>4034189</vid></prop_value><prop_value><name>动物</name><vid>596</vid></prop_value><prop_value><name>字母</name><vid>45576</vid></prop_value><prop_value><name>花卉</name><vid>111408</vid></prop_value><prop_value><name>人物</name><vid>46649</vid></prop_value><prop_value><name>卡通</name><vid>31755</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>true</must><name>09男装-袖长</name><pid>1627743</pid><prop_values list='true'><prop_value><name>长袖（袖长&gt;57cm）</name><vid>3267185</vid></prop_value><prop_value><name>短袖（袖长&lt;35cm）</name><vid>3267186</vid></prop_value><prop_value><name>无袖</name><vid>29446</vid></prop_value><prop_value><name>五分袖</name><vid>14587965</vid></prop_value><prop_value><name>七分袖</name><vid>3216779</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>男装款式（已停用，勿编辑）</name>vb<pid>20609</pid><prop_values list='true'><prop_value><is_parent>true</is_parent><name>羊绒衫</name><vid>3933716</vid></prop_value><prop_value><is_parent>true</is_parent><name>羊毛衫/毛衣</name><vid>136090018</vid></prop_value><prop_value><is_parent>true</is_parent><name>线衫</name><vid>6760069</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>毛线粗细</name><pid>19165355</pid><prop_values list='true'><prop_value><name>细毛线</name><vid>3217108</vid></prop_value><prop_value><name>常规毛线</name><vid>33251159</vid></prop_value><prop_value><name>粗毛线</name><vid>3217106</vid></prop_value><prop_value><name>棒针毛线</name><vid>33251160</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>true</must><name>面料主材质</name><pid>19166310</pid><prop_values list='true'><prop_value><name>纯羊绒</name><vid>3229200</vid></prop_value><prop_value><is_parent>true</is_parent><name>羊绒混纺</name><vid>3229204</vid></prop_value><prop_value><name>纯羊毛</name><vid>3229201</vid></prop_value><prop_value><is_parent>true</is_parent><name>羊毛混纺</name><vid>3229205</vid></prop_value><prop_value><name>纯棉</name><vid>28342</vid></prop_value><prop_value><is_parent>true</is_parent><name>棉质混纺</name><vid>56707543</vid></prop_value><prop_value><name>兔毛</name><vid>21122</vid></prop_value><prop_value><name>马海毛</name><vid>105221</vid></prop_value><prop_value><name>人造纤维</name><vid>18128498</vid></prop_value><prop_value><is_parent>true</is_parent><name>丝</name><vid>3285521</vid></prop_value><prop_value><name>其它</name><vid>10122</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>场合</name><pid>32926</pid><prop_values list='true'><prop_value><name>上班</name><vid>3302158</vid></prop_value><prop_value><name>商务</name><vid>28908</vid></prop_value><prop_value><name>婚礼</name><vid>4060667</vid></prop_value><prop_value><name>居家</name><vid>4068154</vid></prop_value><prop_value><name>旅游</name><vid>27454</vid></prop_value><prop_value><name>正装</name><vid>29536</vid></prop_value><prop_value><name>沙滩</name><vid>103414</vid></prop_value><prop_value><name>舞蹈</name><vid>40809</vid></prop_value><prop_value><name>运动</name><vid>1628</vid></prop_value><prop_value><name>出游</name><vid>139178</vid></prop_value><prop_value><name>宴会</name><vid>139179</vid></prop_value><prop_value><name>逛街</name><vid>139180</vid></prop_value><prop_value><name>休闲</name><vid>29535</vid></prop_value><prop_value><name>雨天</name><vid>17782331</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>年份</name><pid>1626538</pid><prop_values list='true'><prop_value><name>2011</name><vid>3332237</vid></prop_value><prop_value><name>2012</name><vid>3271031</vid></prop_value><prop_value><name>2009</name><vid>3224569</vid></prop_value><prop_value><name>2008</name><vid>123878</vid></prop_value><prop_value><name>2010</name><vid>3224570</vid></prop_value></prop_values></item_prop><item_prop><multi>false</multi><must>false</must><name>消费群体</name><pid>2097794</pid><prop_values list='true'><prop_value><name>老年</name><vid>101181</vid></prop_value><prop_value><name>中年</name><vid>3267960</vid></prop_value><prop_value><name>青少年</name><vid>42007</vid></prop_value><prop_value><name>青年</name><vid>3267959</vid></prop_value><prop_value><name>大码</name><vid>3478795</vid></prop_value></prop_values></item_prop></item_props></itemprops_get_response><!--top050059.cm4-->");
//	 	PagesUtil.outDataToPage("<itemprops_get_response><item_props list=\"true\"><item_prop><name>aaaa</name><prop_values list=\"true\"><prop_value><name>aaaaaa</name></prop_value><prop_value><name>aaaaaa2</name></prop_value></prop_values></item_prop><item_prop><name>aaaa</name><prop_values list=\"true\"><prop_value><name>aaaaaa</name></prop_value><prop_value><name>aaaaaa2</name></prop_value></prop_values></item_prop></item_props></itemprops_get_response>");
		
	}
}
